package com.xiao.community.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.xiao.community.entity.GoodsEntity;
import com.xiao.community.service.GoodsService;
import com.xiao.group.common.utils.R;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiao.group.common.utils.PageUtils;
import com.xiao.group.common.utils.Query;

import com.xiao.community.dao.PintuanDao;
import com.xiao.community.entity.PintuanEntity;
import com.xiao.community.service.PintuanService;


@Service("pintuanService")
public class PintuanServiceImpl extends ServiceImpl<PintuanDao, PintuanEntity> implements PintuanService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<PintuanEntity> wrapper = new QueryWrapper<>();
        IPage<PintuanEntity> page = this.page(
                new Query<PintuanEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Autowired
    GoodsService goodsService ;

    @Autowired
    StringRedisTemplate redisTemplate;

    @Autowired
    RabbitTemplate rabbitTemplate;
    @Override
    public void tosave(PintuanEntity pintuan) throws ParseException {
        GoodsEntity goodsEntity = goodsService.getById(pintuan.getGooGoodsId());
        //0 : 已结束 1: 进行中 2 :未进行
        goodsEntity.setGoodsStatus(2);
        goodsService.updateById(goodsEntity);

        pintuan.setPintuanStatus(0);
        baseMapper.insert(pintuan);

    }

    @Override
    public R tppinlist(Integer pinid) {
        List<PintuanEntity> pintuanEntities = baseMapper.selectList(new QueryWrapper<PintuanEntity>().eq("pintuan_status", 1).eq("goo_goods_id", pinid));
        return R.ok().put("data",pintuanEntities);
    }

}